package com.linx.parking_lot.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.linx.common.idempotent.annotation.RepeatSubmit;
import com.linx.common.log.annotation.Log;
import com.linx.common.web.core.BaseController;
import com.linx.common.mybatis.core.page.PageQuery;
import com.linx.common.core.domain.R;
import com.linx.common.core.validate.AddGroup;
import com.linx.common.core.validate.EditGroup;
import com.linx.common.log.enums.BusinessType;
import com.linx.common.excel.utils.ExcelUtil;
import com.linx.parking_lot.domain.parking_lot_info.ParkingLotInfoVo;
import com.linx.parking_lot.domain.parking_lot_info.ParkingLotInfoBo;
import com.linx.parking_lot.service.IParkingLotInfoService;
import com.linx.common.mybatis.core.page.TableDataInfo;

/**
 * 停车场-信息
 *
 * @author linx
 * @date 2025-02-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/parking-lot/parking-lot-info")
public class ParkingLotInfoController extends BaseController {

    private final IParkingLotInfoService parkingLotInfoService;

    /**
     * 查询停车场-信息列表
     */
    @SaCheckPermission("parking-lot:parking-lot-info:list")
    @GetMapping("/list")
    public TableDataInfo<ParkingLotInfoVo> list(ParkingLotInfoBo query, PageQuery pageQuery) {
        return parkingLotInfoService.queryPageList(query, pageQuery);
    }

    /**
     * 导出停车场-信息列表
     */
    @SaCheckPermission("parking-lot:parking-lot-info:export")
    @Log(title = "停车场-信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ParkingLotInfoBo query, HttpServletResponse response) {
        List<ParkingLotInfoVo> list = parkingLotInfoService.queryList(query);
        ExcelUtil.exportExcel(list, "停车场-信息", ParkingLotInfoVo.class, response);
    }

    /**
     * 获取停车场-信息详细信息
     *
     * @param parkingLotId 主键
     */
    @SaCheckPermission("parking-lot:parking-lot-info:query")
    @GetMapping("/{parkingLotId}")
    public R<ParkingLotInfoVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long parkingLotId) {

        return R.ok(parkingLotInfoService.queryById(parkingLotId));
    }

    /**
     * 新增停车场-信息
     */
    @SaCheckPermission("parking-lot:parking-lot-info:add")
    @Log(title = "停车场-信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ParkingLotInfoBo form) {

        return toAjax(parkingLotInfoService.insertByBo(form));
    }

    /**
     * 修改停车场-信息
     */
    @SaCheckPermission("parking-lot:parking-lot-info:edit")
    @Log(title = "停车场-信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ParkingLotInfoBo form) {

        return toAjax(parkingLotInfoService.updateByBo(form));
    }

    /**
     * 删除停车场-信息
     *
     * @param parkingLotIds 主键串
     */
    @SaCheckPermission("parking-lot:parking-lot-info:remove")
    @Log(title = "停车场-信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{parkingLotIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] parkingLotIds) {

        return toAjax(parkingLotInfoService.deleteWithValidByIds(List.of(parkingLotIds), true));
    }
}
